package com.ruoyi.webs.utils.listener;

import com.ruoyi.webs.utils.DelFileTask;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


public class ContextListener
        implements ServletContextListener {
    private Timer timer = null;


    public void contextInitialized(ServletContextEvent arg0) {
        this.timer = new Timer(true);

        arg0.getServletContext().log("定时器已启动");


        Calendar calendar = Calendar.getInstance();

        calendar.set(11, 9);
        calendar.set(12, 0);
        calendar.set(13, 0);
        Date date = calendar.getTime();


        int period = 86400000;

        this.timer.schedule((TimerTask) new DelFileTask(arg0.getServletContext()), date, period);


        arg0.getServletContext().log("已经添加任务调度表");
    }


    public void contextDestroyed(ServletContextEvent arg0) {
        this.timer.cancel();
        arg0.getServletContext().log("定时器销毁");
    }
}